function [D0i_grid, Di] = ref_percentiles(percentiles,dist_d,d_grid)

% D0i_grid    = round(dist_d.icdf(percentiles)); % Percentiles into values of deposits
D0i_grid    = dist_d.icdf(percentiles); % Percentiles into values of deposits
% Di          = ismember(d_grid,D0i_grid);       % Index in d_grid

%D0i_grid = zeros(size(D0i_grid));
dep      = zeros(size(D0i_grid));
for i = 1:length(D0i_grid)
    [~,dep(i)] = min(abs(d_grid-D0i_grid(i)));
end

Di = zeros(size(d_grid));
Di(dep) = 1;
Di = (Di==1);

D0i_grid = d_grid(Di==1);

end
